#include "processor.h"
#include "server.h"
#include "request.h"
#include "response.h"
#include "thread_pool.h"

#include <iostream>

using namespace std;
using namespace NetKit;

class MyProcessor : public Processor
{
public:
	void HandleStartRequest(Request* pRequest)
	{
		pRequest->SetNeedBytes(1024);
		//cout << "set want bytes be 4" << endl;
	}

	void HandleRequest(Request* pRequest, Response* pResponse)	
	{
		char szResponse[2048];
		char szTmp[1024];
		memset((void*)szTmp, 'a', 1);
		sprintf(szResponse, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", strlen(szTmp), szTmp);
		pResponse->GetBuffer()->SetData(szResponse, strlen(szResponse));
	}
	bool IsGotRequest(Request* pRequest)
	{
		//cout << "get read bytes: " << pRequest->GetReadBytes() << endl;
		//uint32_t len = pRequest->GetBuffer()->GetInt32(0); 
		//cout << "header len: " << len << endl;
		if ( pRequest->GetReadBytes() > 0 )
		{
			//cout << "get request" << endl;
			return true;
		}
		return false;
		/*
		else 
		{
			pRequest->SetWantBytes(4+len);
			return false;
		}
		*/
	}
};

int main(int argc, char** argv)
{
	MyProcessor processor;
	Server svr(&processor);
	svr.Init("conf");
	svr.Run();
	
	return 0;
}

